package com.dic.service;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.dic.dao.UserDao;
import com.dic.dao.WorddictionaryDao;
import com.dic.dao.model.Worddictionary;
import com.dic.util.SqlMapperFactory;

public class WorddictionaryService {

	public List<String> getSubjectNum(String subject){
		List<String> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.getSubjectNum(subject);
			
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
	}
	
	public int updateCompiler(HashMap hm){
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		int updateflag=0;
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			updateflag = wordDao.updateCompiler(hm);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return updateflag;	
	}
	public List<Integer> finishcondition(String subject){
		List<Integer> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.finishcondition(subject);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
		
	}
	public List<Integer> passcondition(String subject){
		List<Integer> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.passcondition(subject);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
		
	}
	
	public List<String> getFinishWordList(HashMap hm){
		List<String> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.getFinishWordList(hm);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
		
		
	}
	public List<String> getPassWordList(HashMap hm){
		List<String> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.getPassWordList(hm);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
		
	}
	public Worddictionary getWord(HashMap hm){
		Worddictionary worddic=new Worddictionary();
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			worddic = wordDao.getWord(hm);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return worddic;
	}
	public int updateWord(Worddictionary worddic){
		int updateflag=0;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			updateflag = wordDao.updateWord(worddic);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return updateflag;
	}
	public int updateWordManage(HashMap hm){
		int updateflag=0;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			updateflag = wordDao.updateWordManage(hm);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return updateflag;
	}
	public List<Worddictionary> getCompilerTask(String compiler){
		List<Worddictionary> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.getCompilerTask(compiler);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
	}
	
	public List<Integer> workerfinishcondition(String compiler){
		List<Integer> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.workerfinishcondition(compiler);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
	}
	
	public List<Integer> workerpasscondition(String compiler){
		List<Integer> lists=null;
		SqlSession session = SqlMapperFactory.getFactory().openSession();
		try {
			WorddictionaryDao wordDao = session.getMapper(WorddictionaryDao.class);
			lists = wordDao.workerpasscondition(compiler);
			session.commit();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return lists;
	}
}
